Skip to content

Reduce flicker when changing fonts/adding tabs in go+=k/fullscreen #1547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

ychin
Copy link
Member

@ychin ychin commented Feb 5, 2025

MacVim would previously show a quick flicker when adjusting font (e.g. Cmd =/-) or showing/hiding tabs/scroll bar when in fixed window size mode (guioptions+=k or full screen). This was because after the state change, Vim requests a resize asynchronously to the GUI to fit it in the window. MacVim does so after changing the font/showing the tab, leading to a momentary incorrect result before Vim then redraws the resized grid. In normal GVim this is not an issue because Vim requests the resize synchronously in a single-process environment, and we would like to avoid that as the message passing between Vim/MacVim and designed to be mostly non-blocking.

To fix this, after receiving the Vim resize request, we block all further text rendering commands, until Vim has resized / redrawn, preventing the short period of time where text view is drawing the old state using the new font. For tabs / scroll bars, the text view itself has moved after the new layout, so we temporarily apply a render offset to make the text view pretend it didn't move and looks mostly the same to the user while we wait for Vim to redraw with the updated grid.

There are some potential ways to still see flicker, but they are mostly edge cases:

  • When changing fonts, if Vim is slow and the user gets MacVim to re-draw the text view (e.g. dragging the window to resize) while we wait for Vim to resize, it would still draw an incorrect result (since it has the new font, but old text grid). This should realistically only happen if Vim takes an abnormal amount of time to respond.
  • For tabs / scrollbars we have a similar issue. We immediately place/remove them while we wait for Vim to resize, which could cause a small visual discontinuity (easiest way is to toggle go+=e). From testing, having the tab bar / etc immediately show up and hide feels better as the user feels like something has happened, so keeping the responsiveness is more important than delaying showing/hiding the tab bar for visual stability (not to mention the deferral is more complicated to implement).

If Vim takes a long time to resize/redraw, this change could make font size change feel less responsive because nothing happens on the screen until the fully redrawn screen is shown. This is ok, and if Vim takes so long to resize then that's the actual issue to address.

This change also removes unnecessary code:

  • Excessive and unnecessary redraws when showing/hiding tabs and setting fonts. They were written a long time ago as temporary hacks which survived till now. From testing this makes changing font size and showing/hiding tabs feel a fair bit more responsive because Vim isn't trying to redraw over and over again now.
  • Stale "maximize" code that has long been unused. It was trying to solve a similar issue but long obsolete and disabled.

@ychin ychin added this to the Release 181 milestone Feb 5, 2025
@ychin
Copy link
Member Author

ychin commented Feb 5, 2025

Just for demonstration:

Flicker from current MacVim:

macvim_old_flicker.mov

No more flicker with this change:

macvim_new_no_flicker.mov

@ychin ychin force-pushed the font-change-newtab-no-flicker branch 2 times, most recently from c3fcd31 to e607fb6 Compare February 5, 2025 12:26
MacVim would previously show a quick flicker when adjusting font (e.g.
Cmd =/-) or showing/hiding tabs/scroll bar when in fixed window size
mode (guioptions+=k or full screen). This was because after the state
change, Vim requests a resize asynchronously to the GUI to fit it in the
window.  MacVim does so after changing the font/showing the tab, leading
to a momentary incorrect result before Vim then redraws the resized
grid. In normal GVim this is not an issue because Vim requests the
resize synchronously in a single-process environment, and we would like
to avoid that as the message passing between Vim/MacVim and designed to
be mostly non-blocking.

To fix this, after receiving the Vim resize request, we block all
further text rendering commands, until Vim has resized / redrawn,
preventing the short period of time where text view is drawing the old
state using the new font. For tabs / scroll bars, the text view itself
has moved after the new layout, so we temporarily apply a render offset
to make the text view pretend it didn't move and looks mostly the same
to the user while we wait for Vim to redraw with the updated grid.

There are some potential ways to still see flicker, but they are mostly
edge cases:

- When changing fonts, if Vim is slow and the user gets MacVim to
  re-draw the text view (e.g. dragging the window to resize) while we
  wait for Vim to resize, it would still draw an incorrect result (since
  it has the new font, but old text grid). This should realistically
  only happen if Vim takes an abnormal amount of time to respond.
- For tabs / scrollbars we have a similar issue. We immediately
  place/remove them while we wait for Vim to resize, which could cause a
  small visual discontinuity (easiest way is to toggle `go+=e`). From
  testing, having the tab bar / etc immediately show up and hide feels
  better as the user feels like something has happened, so keeping the
  responsiveness is more important than delaying showing/hiding the tab
  bar for visual stability (not to mention the deferral is more
  complicated to implement).

If Vim takes a long time to resize/redraw, this change could make font
size change *feel* less responsive because nothing happens on the screen
until the fully redrawn screen is shown. This is ok, and if Vim takes so
long to resize then that's the actual issue to address.

This change also removes unnecessary code:

- Excessive and unnecessary redraws when showing/hiding tabs and setting
  fonts. They were written a long time ago as temporary hacks which
  survived till now. From testing this makes changing font size and
  showing/hiding tabs feel a fair bit more responsive because Vim isn't
  trying to redraw over and over again now.
- Stale "maximize" code that has long been unused. It was trying to solve
  a similar issue but long obsolete and disabled.
@ychin ychin force-pushed the font-change-newtab-no-flicker branch from e607fb6 to 767ffc4 Compare February 5, 2025 13:20
@ychin ychin merged commit dc49d72 into macvim-dev:master Feb 5, 2025
4 checks passed
@ychin ychin deleted the font-change-newtab-no-flicker branch February 5, 2025 18:02
ychin added a commit to ychin/macvim that referenced this pull request Feb 7, 2025
In macvim-dev#1547, flicker during font size change and showing tab/scrollbar were
reduced. Here, we do something similar for the flicker that happens when
entering non-native full screen, where the temporarily moved text view
shows a brief temporary draw before the updated Vim redraws over it,
leading to a flicker. Use the same mechanism here to block rendering and
offset the text view draw to preserve visual stability as much as
possible. No need for native full screen as the smooth but slow
transition means there isn't a sharp flicker anyway.

Also, reduce the "fill right" behavior of Core Text renderer. It's
designed to make smooth resizing more seamless but it fills all the way
to the right which makes situations like this or maximizing the window
jarrying as Vim looks stretched horizontally but not vertically. Just
put a sane cap of 4 cell sizes. This way if Vim is a little slow smooth
resize still looks good, but it won't stretch across the whole screen.
ychin added a commit to ychin/macvim that referenced this pull request Feb 7, 2025
In macvim-dev#1547, flicker during font size change and showing tab/scrollbar were
reduced. Here, we do something similar for the flicker that happens when
entering non-native full screen, where the temporarily moved text view
shows a brief temporary draw before the updated Vim redraws over it,
leading to a flicker. Use the same mechanism here to block rendering and
offset the text view draw while we wait for Vim to preserve visual
stability as much as possible.

No need to do this for native full screen as the smooth but slow
transition means there isn't a sharp flicker anyway.

Also, reduce the "fill right" behavior of Core Text renderer (macvim-dev#1276).
It's designed to make smooth resizing more seamless but it fills all the
way to the right which makes situations like this or maximizing the
window jarrying as Vim looks stretched horizontally but not vertically.
Just put a sane cap of 4 cell sizes. This way if Vim is a little slow
smooth resize still looks good, but it won't stretch across the whole
screen.
ychin added a commit to ychin/macvim that referenced this pull request Feb 7, 2025
In macvim-dev#1547, flicker during font size change and showing tab/scrollbar were
reduced. Here, we do something similar for the flicker that happens when
entering non-native full screen, where the temporarily moved text view
shows a brief temporary draw before the updated Vim redraws over it,
leading to a flicker. Use the same mechanism here to block rendering and
offset the text view draw while we wait for Vim to preserve visual
stability as much as possible.

No need to do this for native full screen as the smooth but slow
transition means there isn't a sharp flicker anyway.

Also, reduce the "fill right" behavior of Core Text renderer (macvim-dev#1276).
It's designed to make smooth resizing more seamless but it fills all the
way to the right which makes situations like this or maximizing the
window jarrying as Vim looks stretched horizontally but not vertically
during the resize before Vim catches up and resizes/redraws. Just put a
sane cap of 4 cell widths. This way even if Vim is a little slow to
respond, smooth resize still looks good, but it won't stretch across the
whole screen.
ychin added a commit to ychin/macvim that referenced this pull request Feb 7, 2025
In macvim-dev#1547, flicker during font size change and showing tab/scrollbar were
reduced. Here, we do something similar for the flicker that happens when
entering non-native full screen, where the temporarily moved text view
shows a brief temporary draw before the updated Vim redraws over it,
leading to a flicker. Use the same mechanism here to block rendering and
offset the text view draw while we wait for Vim to preserve visual
stability as much as possible.

No need to do this for native full screen as the smooth but slow
transition means there isn't a sharp flicker anyway.

Also, reduce the "fill right" behavior of Core Text renderer (macvim-dev#1276).
It's designed to make smooth resizing more seamless but it fills all the
way to the right which makes situations like this or maximizing the
window jarrying as Vim looks stretched horizontally but not vertically
during the resize before Vim catches up and resizes/redraws. Just put a
sane cap of 4 cell widths. This way even if Vim is a little slow to
respond, smooth resize still looks good, but it won't stretch across the
whole screen.
ychin added a commit that referenced this pull request Feb 20, 2025
Updated to Vim 9.1.1128

This update contains a completely new GUI tabs implementation by @sfsam!
It also contains lots of small fixes for window resizing and full screen
mode that aims to make using MacVim feel rock solid and stable.

Defaults Change
====================

New settings defaults related to window sizing #1528:

- "Smoothly resizes window" is now on by default. MacVim's window will
  now resize smoothly instead of snapped to the size of the character
  grid.
- Vim's `guioption` now has `k` set by default (`:h go-k`). This
  prevents MacVim's window size from changing unnecessarily when
  showing/hiding tabs or changing font size.

These should align MacVim better with how other apps work and integrate
better with OS window management, including macOS 15 Sequoia's window
tiling feature.

Features
====================

Tabs
--------------------

MacVim has a new tabs implementation! The old version (PSMTabBarControl)
is not maintained and lacks features such as overflowing tabs and
customizable colors. The new tabs will overflow horizontally and are
scrollable. They also animate when tabs are closed or moved, respect
system settings such as right-to-left locales and high-contrast modes,
and are designed to fit within the currently selected Vim colors.

There are a few ways to customize the colors of the new tabs, under the
"Appearance" settings pane. MacVim defaults to an "Automatic colors"
mode which tries to pick sensible colors automatically based on the
current foreground/background colors. However, you can also configure it
to simply use the tab colors specified by the Vim color scheme (some
color schemes will work better than others depending on their choice of
colors). Another new option is "Use tabs background color" which when
combined with "Transparent title bar" allows the title bar and tabs to
look like a single cohesive whole.

Relevant work:

- #1120 (by @sfsam)
- Also: #1535 / #1536 / #1537 / #1538 / #1539 / #1557 / #1558 / #1560

New Vim features
--------------------

- new bundled color scheme:
    - unokai (vim/vim#16443)
- new bundled optional plugins (use `packadd` to enable them):
    - helptoc: Use `:HelpToc` to show an interactive table of contents
      for Vim help, man pages, Markdown files, and terminal.
      vim/vim#10446
- new options:
    - `set diffopt+=linematch:{n}`. Matches lines better when in diff
      mode. v9.1.1099
    - `findfunc`. Customizes `:find` and other commands. v9.1.0831
    - `set completeopt+=preinsert`. Preview inserted text in completion.
      v9.1.1056
    - `messagesopt`. Allows customizing hit-enter behavior. v9.1.0908
- new functions:
    - `getcellpixels()`. Query the pixel size of a character cell in the
      grid. v9.1.0854 / #1554 / #1555
- Vim tutor has a new interactive plugin (v9.1.0836). There is also now
  a chapter 2 (vim/vim#5729).

Misc New Settings
--------------------

- "Open untitled window" (General) has a new option to only open on
  MacVim re-activation. #1509
- "Show document icon at title bar" (Appearance). Previously MacVim
  implicitly hid the document icon when using transparent title bar.
  This is now customizable. #1510

General
====================

- The MacVim dmg installer has a new design. Courtesy of @jasonlong.
  #1540 #1545
- Legacy builds (macOS 10.9 - 10.12) are no longer built by GitHub
  hosted runners, due to GitHub's deprecation of old runners. They are
  now built by a custom self-hosted VM instead. In the future we hope to
  set up reproducible builds (#1506) so it will not matter who's
  building the app as it would be verifiable. #1559
- "Nightly" build: We now build a dmg installer for every commit. This
  allows for trying out the latest developmental version of MacVim, but
  note that the app will not be signed / notarized, and it will not be
  as polished as official release/pre-release builds. See
  [wiki](https://github.com/macvim-dev/macvim/wiki/Installing) for
  instructions. #1532

Fixes
====================

Apple "Intelligence" Writing Tools
--------------------

macOS 15 Sequoia's Apple "Intelligence" Writing Tools should work
correctly with MacVim now. To use it, select some text, right click to
show menu, and then select the "Writing Tools" sub-menu. As part of this
fix, the integration with the "Services" menu now works more reliably as
well. You can select texts in blockwise visual mode and select a service
and MacVim will try to place the new texts back to the blockwise
selection if possible. #1552

Window resizing and full screen
--------------------

- Flicker begone: Changing font size, showing/hiding tabs or scroll
  bars, or entering non-native full screen should no longer cause MacVim
  to flicker. Previously there could be a momentary but
  distracting/annoying stale image that flashes briefly. #1547 #1549
- Fixed issue where resizing MacVim window would occasionally cause Vim
  to be stuck in a stale wrong size. #1518
- Non-native full screen now supports `blurradius` option. #1546
- Fixed window size not always restoring correctly when exiting full
  screen. Non-native full screen also works more reliably in
  multi-monitor setup. #1525
- Fixed non-native full screen mode when using an external monitor with
  a MacBook with a notch, and having the "Show menu bar in non-native
  mode" option set. Previously MacVim would sometimes miscalculate the
  menu bar height in the second screen. #1548
- Fixed misc issues with non-native full screen's interaction with
  `fuoptions` and also the `transparency` setting, and rare crash. #1521

Other Fixes
--------------------

- Fixed issue where changing font size (using Cmd =/-) with guifont set
  to "-monospace-" would result in guifont being changed to a confusing
  name like ".AppleSystemUIFontMonospaced-Regular". #1544
- "MacVim Website" menu item now goes to the updated URL. #1524
- What's New page now allows changing font size (using Cmd =/-), and
  showing table of contents. #1561 #1562
- Dark mode documentation is now a bit clearer on `v:os_appearance`.
  #1511
- Using dictionary look up on selected texts (by right clicking and then
  selecting "Look Up" in the pop-up menu) is now more resilient as it
  uses Vim's native `getregion()` to determine the selected texts. #1508

Scripting
====================

- Scripting languages versions:
    - Ruby is now built against 3.4, up from 3.3.
    - Perl is now built against 5.34, up from 5.30.

Compatibility
====================

Requires macOS 10.9 or above. (10.9 - 10.12 requires downloading a
separate legacy build)

Script interfaces have compatibility with these versions:

- Lua 5.4
- Perl 5.34
- Python2 2.7
- Python3 3.9 or above
- Ruby 3.4
ychin added a commit that referenced this pull request Feb 21, 2025
Updated to Vim 9.1.1128

This update contains a completely new GUI tabs implementation by @sfsam!
It also contains lots of small fixes for window resizing and full screen
mode that aims to make using MacVim feel rock solid and stable.

Defaults Change
====================

New settings defaults related to window sizing #1528:

- "Smoothly resizes window" is now on by default. MacVim's window will
  now resize smoothly instead of snapped to the size of the character
  grid.
- Vim's `guioption` now has `k` set by default (`:h go-k`). This
  prevents MacVim's window size from changing unnecessarily when
  showing/hiding tabs or changing font size.

These should align MacVim better with how other apps work and integrate
better with OS window management, including macOS 15 Sequoia's window
tiling feature.

Features
====================

Tabs
--------------------

MacVim has a new tabs implementation! The old version (PSMTabBarControl)
is not maintained and lacks features such as overflowing tabs and
customizable colors. The new tabs will overflow horizontally and are
scrollable. They also animate when tabs are closed or moved, respect
system settings such as right-to-left locales and high-contrast modes,
and are designed to fit within the currently selected Vim colors.

There are a few ways to customize the colors of the new tabs, under the
"Appearance" settings pane. MacVim defaults to an "Automatic colors"
mode which tries to pick sensible colors automatically based on the
current foreground/background colors. However, you can also configure it
to simply use the tab colors specified by the Vim color scheme (some
color schemes will work better than others depending on their choice of
colors). Another new option is "Use tabs background color" which when
combined with "Transparent title bar" allows the title bar and tabs to
look like a single cohesive whole.

Relevant work:

- #1120 (by @sfsam)
- Also: #1535 / #1536 / #1537 / #1538 / #1539 / #1557 / #1558 / #1560

New Vim features
--------------------

- new bundled color scheme:
    - unokai (vim/vim#16443)
- new bundled optional plugins (use `packadd` to enable them):
    - helptoc: Use `:HelpToc` to show an interactive table of contents
      for Vim help, man pages, Markdown files, and terminal.
      vim/vim#10446
- new options:
    - `set diffopt+=linematch:{n}`. Matches lines better when in diff
      mode. v9.1.1099
    - `findfunc`. Customizes `:find` and other commands. v9.1.0831
    - `set completeopt+=preinsert`. Preview inserted text in completion.
      v9.1.1056
    - `messagesopt`. Allows customizing hit-enter behavior. v9.1.0908
- new functions:
    - `getcellpixels()`. Query the pixel size of a character cell in the
      grid. v9.1.0854 / #1554 / #1555
- Vim tutor has a new interactive plugin (v9.1.0836). There is also now
  a chapter 2 (vim/vim#5729).

Misc New Settings
--------------------

- "Open untitled window" (General) has a new option to only open on
  MacVim re-activation. #1509
- "Show document icon at title bar" (Appearance). Previously MacVim
  implicitly hid the document icon when using transparent title bar.
  This is now customizable. #1510

General
====================

- The MacVim dmg installer has a new design. Courtesy of @jasonlong.
  #1540 #1545
- Legacy builds (macOS 10.9 - 10.12) are no longer built by GitHub
  hosted runners, due to GitHub's deprecation of old runners. They are
  now built by a custom self-hosted VM instead. In the future we hope to
  set up reproducible builds (#1506) so it will not matter who's
  building the app as it would be verifiable. #1559
- "Nightly" build: We now build a dmg installer for every commit. This
  allows for trying out the latest developmental version of MacVim, but
  note that the app will not be signed / notarized, and it will not be
  as polished as official release/pre-release builds. See
  [wiki](https://github.com/macvim-dev/macvim/wiki/Installing) for
  instructions. #1532

Fixes
====================

Apple "Intelligence" Writing Tools
--------------------

macOS 15 Sequoia's Apple "Intelligence" Writing Tools should work
correctly with MacVim now. To use it, select some text, right click to
show menu, and then select the "Writing Tools" sub-menu. As part of this
fix, the integration with the "Services" menu now works more reliably as
well. You can select texts in blockwise visual mode and select a service
and MacVim will try to place the new texts back to the blockwise
selection if possible. #1552

Window resizing and full screen
--------------------

- Flicker begone: Changing font size, showing/hiding tabs or scroll
  bars, or entering non-native full screen should no longer cause MacVim
  to flicker. Previously there could be a momentary but
  distracting/annoying stale image that flashes briefly. #1547 #1549
- Fixed issue where resizing MacVim window would occasionally cause Vim
  to be stuck in a stale wrong size. #1518
- Non-native full screen now supports `blurradius` option. #1546
- Fixed window size not always restoring correctly when exiting full
  screen. Non-native full screen also works more reliably in
  multi-monitor setup. #1525
- Fixed non-native full screen mode when using an external monitor with
  a MacBook with a notch, and having the "Show menu bar in non-native
  mode" option set. Previously MacVim would sometimes miscalculate the
  menu bar height in the second screen. #1548
- Fixed misc issues with non-native full screen's interaction with
  `fuoptions` and also the `transparency` setting, and rare crash. #1521

Other Fixes
--------------------

- Fixed issue where changing font size (using Cmd =/-) with guifont set
  to "-monospace-" would result in guifont being changed to a confusing
  name like ".AppleSystemUIFontMonospaced-Regular". #1544
- "MacVim Website" menu item now goes to the updated URL. #1524
- What's New page now allows changing font size (using Cmd =/-), and
  showing table of contents. #1561 #1562
- Dark mode documentation is now a bit clearer on `v:os_appearance`.
  #1511
- Using dictionary look up on selected texts (by right clicking and then
  selecting "Look Up" in the pop-up menu) is now more resilient as it
  uses Vim's native `getregion()` to determine the selected texts. #1508

Scripting
====================

- Scripting languages versions:
    - Ruby is now built against 3.4, up from 3.3.
    - Perl is now built against 5.34, up from 5.30.

Compatibility
====================

Requires macOS 10.9 or above. (10.9 - 10.12 requires downloading a
separate legacy build)

Script interfaces have compatibility with these versions:

- Lua 5.4
- Perl 5.34
- Python2 2.7
- Python3 3.9 or above
- Ruby 3.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant